
setPage();

function setPage() {

    const mes = JSON.parse(window.localStorage.mes);

    let str = '';
    mes.forEach(item =>{

        str += `
                <tr>
                 <td>${item.name}</td>
                 <td>${item.phoneNum}</td>
                 <td>${item.degree}</td>
                 <td>${item.age}</td>
                 <td>${item.salary}</td>
                 <td><button>修改</button> <button>删除</button></td>
                </tr> 
        `
    })
    $('tbody').html(str);
}


$('.box').click(function(event) {

    event.preventDefault();

    // const mes = JSON.parse(window.localStorage.mes);

    // let name = $('[name="name"]').val();
    // let phoneNum = $('[name="phoneNum"]').val();
    // let degree = $('[name="degree"]').val();
    // let age = $('[name="age"]').val();
    // let salary = $('[name="salary"]').val();
    window.localStorage.setItem('obj',JSON.stringify({name:name,phoneNum:phoneNum,degree:degree,age:age,salary:salary}))

   if ($(event.target).attr('name') === 'save') {
       
       if (window.localStorage.mes === undefined) {
           let mes = {};
            mes.name = $('[name="name"]').val();
            mes.phoneNum = $('[name="phoneNum"]').val();
            mes.degree = $('[name="degree"]').val();
            mes.age = $('[name="age"]').val();
            mes.salary = $('[name="salary"]').val();
        }
    
   }

   window.localStorage.mes = JSON.stringify([mes]);
   setPage();
})


